<!-- 注册
 1. vue始终在用双向绑定的思想来准备前后端交互，每一个vue都会定义好变量给 表单（form）或者表格（table）中的html元素的值绑定
-->
<template>
  <div><!-- element组件库的Dialog对话框默认可以通过点击 modal 关闭 Dialog，即点击空白处弹框可关闭。 -->
    <!-- :visible.sync 子组键改变父组件的值 控制子组件的显示-->
    <el-dialog title="标题名" :visible.sync="addDialogIsShow" :before-close="handleClose" :close-on-click-modal="false">
      <el-form  :model="order" label-width="80px" :rules="addOrderRules" ref="addOrderForm">
        <el-form-item label="下单日期">
          <el-col :span="8">
            <el-input v-model="order.date"></el-input>
          </el-col></el-form-item>
        <el-form-item label="下单桌数">
          <el-col :span="18">
            <el-input v-model="order.pic"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="定金">
          <el-col :span="18">
            <el-input v-model="order.pic"></el-input>
          </el-col>
        </el-form-item>
      </el-form>

      <span>
      <el-button type="success" @click="addOrder('addOrderForm')">注册</el-button>
    </span>
    </el-dialog>
  </div>
</template>

<script>
  import rules from "../../../../static/js/validator/rules.js"
  import utils from "../../../../static/js/utils/index.js"
  export default {
    name: "addOrder",
    data(){
      return {order:{name:"",pic:"",date:""},
        addDialogIsShow: false,
        addOrderRules:{name:[{required:true,message:"球队名称不能为空",trigger:'blur'},
            {max:20,min:2,message:'长度异常 长度在2-20之间',trigger:'blur'},{pattern:/^[\u0391-\uFFE5A-Za-z]+$/,message:'球队名称必须为中文',trigger:'blur'}]}
      }
    },
    methods: {
      addOrder:function(addOrderForm){
        this.$refs[addOrderForm].validate(valid => {//此处refs对象和标签上的ref对应
          if (valid) {
            //如果通过验证 to do...
            console.log(this.order);
            alert(this.$store.state.host);
            alert(this.order.name+"添加成功");
            this.handleClose();
          } else {
            console.log('error submit!!')
            return false
          }
        })},
      //页面初始化时加载的事件
      init(date) {
        console.log(date);
        this.addDialogIsShow = true;
        this.order.date = utils.FD.Fd().initCNDate(date);
      },

      //关闭页面
      handleClose() {
        this.addDialogIsShow = false;
        //给父组件传参
        this.$emit("addDialogIsShow", this.addDialogIsShow);
      }
    },

    //监听
    watch: {
      dialogisShow(newValue, oldValue) {
        this.addDialogIsShow = newValue;
      }
    }

  }
</script>

<style scoped>

</style>
